package com.twu.biblioteca;

import jxl.Sheet;
import jxl.Workbook;

import java.io.FileInputStream;
import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * User: twer
 * Date: 10/10/13
 * Time: 10:14 AM
 * To change this template use File | Settings | File Templates.
 */
public class ReadMovieFile {
    private ArrayList<Movie> _movies = new ArrayList<Movie>();
    private String _filePath;

    public void setFilePath(String filePath){
        _filePath = filePath;
    }

    public ArrayList<Movie> readFile() {
        Workbook book;
        Sheet sheet;

        try {
            book = Workbook.getWorkbook(new FileInputStream(_filePath));
            sheet = book.getSheet(0);

            for (int i=1;i<sheet.getRows();i++){
                Movie movie = new Movie();
                movie.setName(sheet.getRow(i)[0].getContents());
                movie.setYear(sheet.getRow(i)[1].getContents());
                movie.setDirector(sheet.getRow(i)[2].getContents());
                movie.setRating(sheet.getRow(i)[3].getContents());

                _movies.add(movie);
            }

        }catch (Exception e){

        }

        return _movies;
    }

}
